﻿namespace Smart.ERP
{
    using Smart.Data.Helper;
    using Smart.Utils.Lib;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Windows.Forms;

    public class SYS_LOG
    {
        private int m_Action;
        private string m_Action_Name;
        private bool m_Active;
        private DateTime m_Created;
        private string m_Description;
        private string m_IP;
        private string m_MChine;
        private string m_Module;
        private string m_Reference;
        private long m_SYS_ID;
        private string m_UserID;

        public SYS_LOG()
        {
            this.m_SYS_ID = 0L;
            this.m_MChine = "";
            this.m_IP = "";
            this.m_UserID = "";
            this.m_Created = DateTime.Now;
            this.m_Module = "";
            this.m_Action = 0;
            this.m_Action_Name = "";
            this.m_Reference = "";
            this.m_Description = "";
            this.m_Active = true;
        }

        public SYS_LOG(long SYS_ID, string MChine, string IP, string UserID, DateTime Created, string Module, int Action, string Action_Name, string Reference, string Description, bool Active)
        {
            this.m_SYS_ID = SYS_ID;
            this.m_MChine = MChine;
            this.m_IP = IP;
            this.m_UserID = UserID;
            this.m_Created = Created;
            this.m_Module = Module;
            this.m_Action = Action;
            this.m_Action_Name = Action_Name;
            this.m_Reference = Reference;
            this.m_Description = Description;
            this.m_Active = Active;
        }

        public void AddCombo(ComboBox combo)
        {
            MyLib.TableToComboBox(combo, this.GetList(), "SYS_LOGName", "SYS_LOGID");
        }

        public void AddComboAll(ComboBox combo)
        {
            DataTable list = new DataTable();
            list = this.GetList();
            DataRow row = list.NewRow();
            row["SYS_LOGID"] = "All";
            row["SYS_LOGName"] = "Tất cả";
            list.Rows.InsertAt(row, 0);
            MyLib.TableToComboBox(combo, list, "SYS_LOGName", "SYS_LOGID");
        }

        public string Delete()
        {
            string[] myParams = new string[] { "@SYS_ID" };
            object[] myValues = new object[] { this.m_SYS_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_LOG_Delete", myParams, myValues);
        }

        public string Delete(long SYS_ID)
        {
            string[] myParams = new string[] { "@SYS_ID" };
            object[] myValues = new object[] { SYS_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_LOG_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, long SYS_ID)
        {
            string[] myParams = new string[] { "@SYS_ID" };
            object[] myValues = new object[] { SYS_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "SYS_LOG_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, long SYS_ID)
        {
            string[] myParams = new string[] { "@SYS_ID" };
            object[] myValues = new object[] { SYS_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "SYS_LOG_Delete", myParams, myValues);
        }

        public bool Exist(long SYS_ID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@SYS_ID" };
            object[] myValues = new object[] { SYS_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("SYS_LOG_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Get(long SYS_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@SYS_ID" };
            object[] myValues = new object[] { SYS_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("SYS_LOG_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_SYS_ID = Convert.ToInt64(reader["SYS_ID"]);
                    this.m_MChine = Convert.ToString(reader["MChine"]);
                    this.m_IP = Convert.ToString(reader["IP"]);
                    this.m_UserID = Convert.ToString(reader["UserId"]);
                    this.m_Created = Convert.ToDateTime(reader["Created"]);
                    this.m_Module = Convert.ToString(reader["Module"]);
                    this.m_Action = Convert.ToInt32(reader["Action"]);
                    this.m_Action_Name = Convert.ToString(reader["Action_Name"]);
                    this.m_Reference = Convert.ToString(reader["Reference"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, long SYS_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@SYS_ID" };
            object[] myValues = new object[] { SYS_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "SYS_LOG_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_SYS_ID = Convert.ToInt64(reader["SYS_ID"]);
                    this.m_MChine = Convert.ToString(reader["MChine"]);
                    this.m_IP = Convert.ToString(reader["IP"]);
                    this.m_UserID = Convert.ToString(reader["UserId"]);
                    this.m_Created = Convert.ToDateTime(reader["Created"]);
                    this.m_Module = Convert.ToString(reader["Module"]);
                    this.m_Action = Convert.ToInt32(reader["Action"]);
                    this.m_Action_Name = Convert.ToString(reader["Action_Name"]);
                    this.m_Reference = Convert.ToString(reader["Reference"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, long SYS_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@SYS_ID" };
            object[] myValues = new object[] { SYS_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "SYS_LOG_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_SYS_ID = Convert.ToInt64(reader["SYS_ID"]);
                    this.m_MChine = Convert.ToString(reader["MChine"]);
                    this.m_IP = Convert.ToString(reader["IP"]);
                    this.m_UserID = Convert.ToString(reader["UserId"]);
                    this.m_Created = Convert.ToDateTime(reader["Created"]);
                    this.m_Module = Convert.ToString(reader["Module"]);
                    this.m_Action = Convert.ToInt32(reader["Action"]);
                    this.m_Action_Name = Convert.ToString(reader["Action_Name"]);
                    this.m_Reference = Convert.ToString(reader["Reference"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetList()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("SYS_LOG_GetList");
        }

        public DataTable GetList(DateTime from, DateTime to)
        {
            string[] myParams = new string[] { "@From", "@To" };
            object[] myValues = new object[] { from, to };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("SYS_LOG_GetList_ByDate", myParams, myValues);
        }

        public string Insert()
        {
            string[] myParams = new string[] { "@SYS_ID", "@MChine", "@IP", "@UserId", "@Created", "@Module", "@Action", "@Action_Name", "@Reference", "@Description", "@Active" };
            object[] myValues = new object[] { this.m_SYS_ID, this.m_MChine, this.m_IP, this.m_UserID, this.m_Created, this.m_Module, this.m_Action, this.m_Action_Name, this.m_Reference, this.m_Description, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_LOG_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@SYS_ID", "@MChine", "@IP", "@UserId", "@Created", "@Module", "@Action", "@Action_Name", "@Reference", "@Description", "@Active" };
            object[] myValues = new object[] { this.m_SYS_ID, this.m_MChine, this.m_IP, this.m_UserID, this.m_Created, this.m_Module, this.m_Action, this.m_Action_Name, this.m_Reference, this.m_Description, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "SYS_LOG_Insert", myParams, myValues);
        }

        public static string Insert(string Module, string Action_Name)
        {
            string[] myParams = new string[] { "@MChine", "@IP", "@UserId", "@Created", "@Module", "@Action", "@Action_Name", "@Reference", "@Description", "@Active" };
            object[] myValues = new object[] { Environment.MachineName, Environment.MachineName, MyLogin.UserId, DateTime.Now, Module, 0, Action_Name, "", Action_Name + " " + Module, true };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_LOG_Insert", myParams, myValues);
        }

        public static string Insert(string Module, string Action_Name, string Reference)
        {
            string[] myParams = new string[] { "@MChine", "@IP", "@UserId", "@Created", "@Module", "@Action", "@Action_Name", "@Reference", "@Description", "@Active" };
            object[] myValues = new object[] { Environment.MachineName, Environment.MachineName, MyLogin.UserId, DateTime.Now, Module, 0, Action_Name, Reference, Action_Name + " " + Module + " - " + Reference, true };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_LOG_Insert", myParams, myValues);
        }

        public string Insert(long SYS_ID, string MChine, string IP, string UserID, DateTime Created, string Module, int Action, string Action_Name, string Reference, string Description, bool Active)
        {
            string[] myParams = new string[] { "@SYS_ID", "@MChine", "@IP", "@UserId", "@Created", "@Module", "@Action", "@Action_Name", "@Reference", "@Description", "@Active" };
            object[] myValues = new object[] { SYS_ID, MChine, IP, UserID, Created, Module, Action, Action_Name, Reference, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_LOG_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, long SYS_ID, string MChine, string IP, string UserID, DateTime Created, string Module, int Action, string Action_Name, string Reference, string Description, bool Active)
        {
            string[] myParams = new string[] { "@SYS_ID", "@MChine", "@IP", "@UserId", "@Created", "@Module", "@Action", "@Action_Name", "@Reference", "@Description", "@Active" };
            object[] myValues = new object[] { SYS_ID, MChine, IP, UserID, Created, Module, Action, Action_Name, Reference, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "SYS_LOG_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, long SYS_ID, string MChine, string IP, string UserID, DateTime Created, string Module, int Action, string Action_Name, string Reference, string Description, bool Active)
        {
            string[] myParams = new string[] { "@SYS_ID", "@MChine", "@IP", "@UserId", "@Created", "@Module", "@Action", "@Action_Name", "@Reference", "@Description", "@Active" };
            object[] myValues = new object[] { SYS_ID, MChine, IP, UserID, Created, Module, Action, Action_Name, Reference, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "SYS_LOG_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return SqlHelper.GenCode("SYS_LOG", "SYS_LOGID", "");
        }

        public string Update()
        {
            string[] myParams = new string[] { "@SYS_ID", "@MChine", "@IP", "@UserId", "@Created", "@Module", "@Action", "@Action_Name", "@Reference", "@Description", "@Active" };
            object[] myValues = new object[] { this.m_SYS_ID, this.m_MChine, this.m_IP, this.m_UserID, this.m_Created, this.m_Module, this.m_Action, this.m_Action_Name, this.m_Reference, this.m_Description, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_LOG_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@SYS_ID", "@MChine", "@IP", "@UserId", "@Created", "@Module", "@Action", "@Action_Name", "@Reference", "@Description", "@Active" };
            object[] myValues = new object[] { this.m_SYS_ID, this.m_MChine, this.m_IP, this.m_UserID, this.m_Created, this.m_Module, this.m_Action, this.m_Action_Name, this.m_Reference, this.m_Description, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "SYS_LOG_Update", myParams, myValues);
        }

        public string Update(long SYS_ID, string MChine, string IP, string UserID, DateTime Created, string Module, int Action, string Action_Name, string Reference, string Description, bool Active)
        {
            string[] myParams = new string[] { "@SYS_ID", "@MChine", "@IP", "@UserId", "@Created", "@Module", "@Action", "@Action_Name", "@Reference", "@Description", "@Active" };
            object[] myValues = new object[] { SYS_ID, MChine, IP, UserID, Created, Module, Action, Action_Name, Reference, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_LOG_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, long SYS_ID, string MChine, string IP, string UserID, DateTime Created, string Module, int Action, string Action_Name, string Reference, string Description, bool Active)
        {
            string[] myParams = new string[] { "@SYS_ID", "@MChine", "@IP", "@UserId", "@Created", "@Module", "@Action", "@Action_Name", "@Reference", "@Description", "@Active" };
            object[] myValues = new object[] { SYS_ID, MChine, IP, UserID, Created, Module, Action, Action_Name, Reference, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "SYS_LOG_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, long SYS_ID, string MChine, string IP, string UserID, DateTime Created, string Module, int Action, string Action_Name, string Reference, string Description, bool Active)
        {
            string[] myParams = new string[] { "@SYS_ID", "@MChine", "@IP", "@UserId", "@Created", "@Module", "@Action", "@Action_Name", "@Reference", "@Description", "@Active" };
            object[] myValues = new object[] { SYS_ID, MChine, IP, UserID, Created, Module, Action, Action_Name, Reference, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "SYS_LOG_Update", myParams, myValues);
        }

        public int Action
        {
            get
            {
                return this.m_Action;
            }
            set
            {
                this.m_Action = value;
            }
        }

        public string Action_Name
        {
            get
            {
                return this.m_Action_Name;
            }
            set
            {
                this.m_Action_Name = value;
            }
        }

        public bool Active
        {
            get
            {
                return this.m_Active;
            }
            set
            {
                this.m_Active = value;
            }
        }

        public DateTime Created
        {
            get
            {
                return this.m_Created;
            }
            set
            {
                this.m_Created = value;
            }
        }

        public string Description
        {
            get
            {
                return this.m_Description;
            }
            set
            {
                this.m_Description = value;
            }
        }

        public string IP
        {
            get
            {
                return this.m_IP;
            }
            set
            {
                this.m_IP = value;
            }
        }

        public string MChine
        {
            get
            {
                return this.m_MChine;
            }
            set
            {
                this.m_MChine = value;
            }
        }

        public string Module
        {
            get
            {
                return this.m_Module;
            }
            set
            {
                this.m_Module = value;
            }
        }

        public string ProductName
        {
            get
            {
                return "Class SYS_LOG";
            }
        }

        public string ProductVersion
        {
            get
            {
                return "1.0.0.0";
            }
        }

        public string Reference
        {
            get
            {
                return this.m_Reference;
            }
            set
            {
                this.m_Reference = value;
            }
        }

        public long SYS_ID
        {
            get
            {
                return this.m_SYS_ID;
            }
            set
            {
                this.m_SYS_ID = value;
            }
        }

        public string UserID
        {
            get
            {
                return this.m_UserID;
            }
            set
            {
                this.m_UserID = value;
            }
        }
    }
}

